package leetcode.code163.MissingRanges;

import java.util.ArrayList;
import java.util.List;

public class Solution16301 extends MissingRanges {

	@Override
	public List<String> findMissingRanges(int[] nums, int lower, int upper) {
		List<String> result = new ArrayList<>();
		if (nums == null || nums.length == 0) {
			result.add(ranges(lower, upper));
			return result;
		}
		int len = nums.length;
		String range = this.ranges(lower, nums[0] - 1);
		if (range != null)
			result.add(range);
		for (int i = 0; i < len - 1; i++) {
			range = this.ranges(nums[i] + 1, nums[i + 1] - 1);
			if (range != null)
				result.add(range);
		}
		range = this.ranges(nums[len - 1] + 1, upper);
		if (range != null)
			result.add(range);
		return result;
	}

	public String ranges(int lower, int upper) {
		if (lower > upper) {
			return null;
		}
		return lower != upper ? lower + "->" + upper : lower + "";
	}

	public static void main(String[] args) {
		Solution16301 so = new Solution16301();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();
	}

}
